package com.qf.lanzhou.blog.api.controller.tag;

import com.qf.lanzhou.blog.api.controller.BaseServletPost;
import com.qf.lanzhou.blog.api.pojo.entity.Tag;
import com.qf.lanzhou.blog.api.service.TagService;
import com.qf.lanzhou.blog.api.service.impl.TagServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author Nerly
 * @Date 2020/12/19 17:06
 * @JDK 1.8
 * @Version 1.0
 */
@WebServlet("/updateTag.do")
public class UpdateTagServlet extends BaseServletPost {
    private TagService tagService = new TagServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("updateTag.do doPost");
        Tag tag = paramsToEntity(req, Tag.class);
        String errMsg = tagService.updateTag(tag);
        if (errMsg != null) {
            //返回前端错误信息
            failedResultWrite(errMsg, resp);
            return;
        }
        //返回成功信息
        successResultWrite(tag, resp);
    }
}
